package com.minelx.statementsplus.cha.base.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;

public class DoWorkResponse {

	private final JSONObject responseAsJSON;

	public DoWorkResponse(String source) {
		// FIXME 2021/8/9  wait for me!!!    test edge
		try {
			responseAsJSON = JSON.parseObject(source);
		} catch (JSONException e) {
			throw new IllegalArgumentException("illegal source: " + source, e);
		}
	}

	public boolean isSuccess() {
		return responseAsJSON.getIntValue("f") == 1;
	}

	public String message() {
		return responseAsJSON.getString("m");
	}

	public int bval() {
		return responseAsJSON.getIntValue("bval");
	}

	public int progress() {
		return responseAsJSON.getIntValue("ttl");
	}

	@Override
	public String toString() {
		return "DoWorkResponse{" +
				"responseAsJSON=" + responseAsJSON +
				'}';
	}
}
